package com.zm.demo.core.concurrent;

import static java.lang.System.out;

/**
 * Created by Administrator on 2020/1/16.
 */
public class VolatileTest {

    volatile int i=0;

    public static void main(String[]args){

        new VolatileTest().test();

    }

    public void test(){
        Thread t1 = new Thread(() ->{
            for (int j = 0; j < 10; j++) {
                out.println(i++);
            }
        });
        Thread t2 = new Thread(() ->{
            for (int j = 0; j < 10; j++) {
                out.println(i++);
            }
        });
        Thread t3 = new Thread(() ->{
            for (int j = 0; j < 10; j++) {
                out.println(i++);
            }
        });

        t1.start();
        t2.start();
        t3.start();
    }
}
